﻿using System;

class SettingBitAtPosition
{
    static void Main()
    {
        Console.WriteLine("Enter an integer number:");
        int number = Int32.Parse(Console.ReadLine());
        Console.WriteLine("Enter bit position (from 0 to 31):");
        int bitPosition = Int32.Parse(Console.ReadLine());
        Console.WriteLine("Enter bit value (0 or 1):");
        int bitValue = Int32.Parse(Console.ReadLine());
        int mask;
        int result;

        if ((bitPosition >= 0) && (bitPosition <= 31) && (bitValue >= 0) && (bitValue <= 1))
        {

            if (bitValue == 0)
            {
                mask = ~(1 << bitPosition);
                result = number & mask;
                Console.WriteLine("After setting bit {0} to 0 we get the number {1}.", bitPosition, result);
            }
            else
            {
                mask = 1 << bitPosition;
                result = number | mask;
                Console.WriteLine("After setting bit {0} to 1 we get the number {1}.", bitPosition, result);
            }
        }
        else
        {
            Console.WriteLine("Invalid values.");
        }
    }
}